import React from 'react'
// ===================================================================== Temp
import SearchForm from '#cpt/temp/SearchForm'
import Table from '#cpt/temp/Table'
// ===================================================================== global declare
const { $fn, $Lazy } = window
// ===================================================================== $Lazy
const $cache 		= $Lazy.file(()=>import('#private/cache-api'))
const $time 		= $Lazy.file(()=>import('@com/utils/time'))
// ===================================================================== data
const sourceData = [{name:'在线商城',value:'1'},{name:'物流小程序',value:'2'},{name:'采样小程序',value:'3'},{name:'未知来源',value:'0'}]
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		// 搜索表单列表
		forms : [
			{ label: '条码号',		name: 'spec_code' },
			{ label: '项目名称',		name: 'kind_code',		type:'select',	loading:true },
			{ label: '姓名',		name: 'check_name' },
			{ label: '创建日期',		names: ['start_at','end_at'], 	type:'date-range', 	loading:true,	name:'jz-time' },
			{ label: '手机号',		name: 'check_phone' },
			{ label: '证件号',		name: 'card_no' },
			// 添加来源  2022-5-24  --马婷
			{ label: '来源',		name: 'source',		type:'select',	data:sourceData },
		]
	}
	componentDidMount(){
		this.getSelect()
		
		$time.then(f=>{				 /* 添加默认创建时间 2022-5-24 --马婷 */
			const arr = f.duration['30']()
			this.resetModel = { start_at: arr[0], end_at: arr[1], 'jz-time':arr }
			this.model = $fn.copy(this.resetModel)
			if(window.isInit){
				this.fetch()
			}
		})
		
	}
	// 获取下拉数据
	getSelect = () => {
		const { forms } = this.state
		$cache.then( async f => {
			// 项目名称
			$fn.setRow( forms, 'kind_code', await f.getCache({ api:'combinKindSelect' }) )
			
			this.setState({ forms })
		})
	}
	// 弹窗获取下拉数据
	getModalSelect = () => {
		const { formData } = this.state
		$cache.then( async f => {
			//标本箱号
			$fn.setRow( formData, 'box_code', await f.getCache({ api:'box/select',param:{status:81,limit:1000},way:'post',refresh:true}) )
			
			this.setState({ formData })
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'internet-gather/index', {isIndex:true,param:{is_delete:'2'}})
	
	// 表单
	cols = [
		{ title: '条码号', 		dataIndex: 'spec_code', 		...$fn.table.spec_code },
		{ title: '项目名称', 	dataIndex: 'kind_name', 		width:180 },
		{ title: '姓名', 		dataIndex: 'check_name', 		...$fn.table.name },
		{ title: '年龄', 		dataIndex: 'age', 				width:60 },
		{ title: '性别', 		dataIndex: 'sex', 				width:60,		render: text => {
			switch (+text){
				case 45701:
					return '男';
				case 45702:
					return '女';
				default:
					return '/';
			}
		} },
		{ title: '医院', 		dataIndex: 'hosp_name', 	width:180 },
		{ title: '来源', 		dataIndex: 'source_name', 	width:120 },
		{ title: '手机号', 		dataIndex: 'check_phone', 	...$fn.table.phone },
		{ title: '证件类型', 	dataIndex: 'card_type_name', ...$fn.table.card_type },
		{ title: '证件号', 		dataIndex: 'card_no', 		...$fn.table.idcard },
		{ title: '创建时间', 	dataIndex: 'created_at',  	...$fn.table.time},
		{ title: '操作人', 		dataIndex: 'operator_name',	...$fn.table.name},
		{ title: '操作时间', 	dataIndex: 'delete_at',		...$fn.table.time},
	]
	
	// 操作按钮
	controls = ()=> []
	
	render(){
		return (
		<>
			{/* 搜索 */}
			{ SearchForm.call(this, {timeStr:'30'}) }
			{/* 表格 */}
			{ Table.call(this, {isIndex:true, isInit: window.isInit}) }
		</>
			
		)
	}
}

export default Index
 /* 标本管理添加云采集页面 2021-8-10 --马婷 */